/*
 * TiberiumTheme.java
 *
 * Copyright 2007 Tiberiumlabs
 *
 * This file is part of Tiberiumlabs Shards.
 *
 * Tiberiumlabs Shards is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * Tiberiumlabs Shards is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.tiberiumlabs.shards.theme;

import java.awt.Color;
import java.util.Arrays;
import java.util.List;
import javax.swing.ToolTipManager;
import javax.swing.UIDefaults;
import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.metal.OceanTheme;

/**
 * Theme with no cyan colors. using gray-to-gray gradient for buttons,
 * yellow background for tooltips, plain fonts (not bold like in default swing),
 * grey selection background for text fields.
 * 
 * @author <a href="mailto:paranoid.tiberiumlabs@gmail.com">Paranoid</a>
 */
public class TiberiumTheme extends OceanTheme {
    
    private static final ColorUIResource GRAY_DARK = new ColorUIResource(192, 202, 209);
    private static final ColorUIResource GRAY_BLACK = new ColorUIResource(100, 110, 120);

    @Override
    public void addCustomEntriesToTable(UIDefaults table) {
        
        super.addCustomEntriesToTable(table);

        Color grayLighter = new ColorUIResource(223, 228, 231);
        Color grayDarker = GRAY_DARK;
        Color yellow = new Color(255, 255, 220);

        List buttonGradient = Arrays.asList(
                new Object[] {new Float(0f), new Float(0f),
                grayLighter, Color.WHITE, grayDarker });

        Object[] defaults = new Object[] {
            "swing.boldMetal", Boolean.FALSE,

            // set gradient:
            "Button.gradient", buttonGradient,
            "CheckBox.gradient", buttonGradient,
            "CheckBoxMenuItem.gradient", buttonGradient,
            "InternalFrame.activeTitleGradient", buttonGradient,
            "RadioButton.gradient", buttonGradient,
            "RadioButtonMenuItem.gradient", buttonGradient,
            "ScrollBar.gradient", buttonGradient,
            "ToggleButton.gradient", buttonGradient,
            "Slider.gradient", buttonGradient,
            "Slider.focusGradient", Arrays.asList(
                new Object[] {new Float(.3f), new Float(.2f),
                grayDarker, grayLighter, GRAY_BLACK }),

            // elements colors:
            "TextField.focused", yellow,
            
            "TextField.selectionForeground", yellow,
            "TextField.selectionBackground", GRAY_BLACK,
            
            "PasswordField.selectionForeground", yellow,
            "PasswordField.selectionBackground", GRAY_BLACK,
            
            "TextArea.selectionForeground", yellow,
            "TextArea.selectionBackground", GRAY_BLACK,
            
            "ToolTip.background", yellow,
            
            "Table.gridColor", grayDarker,
            "Table.selectionForeground", yellow,
            "Table.selectionBackground", GRAY_BLACK,
            
            "Tree.selectionForeground", yellow,
            "Tree.selectionBackground", GRAY_BLACK,
            
            "List.selectionForeground", yellow,
            "List.selectionBackground", GRAY_BLACK,
            "List.alternativeBackground", new Color(240, 240, 240),
            
            "ComboBox.selectionForeground", yellow,
            "ComboBox.selectionBackground", GRAY_BLACK,
            "ComboBox.background", grayLighter,
            
            "ProgressBar.foreground", GRAY_BLACK, // filler color
            "ProgressBar.selectionForeground", yellow, // color of text on filled part
            "ProgressBar.selectionBackground", GRAY_BLACK, // color of text on clear part
            
            "Menu.selectionBackground", GRAY_BLACK,
            "Menu.selectionForeground", yellow,
            "MenuItem.selectionBackground", GRAY_BLACK,
            "MenuItem.selectionForeground", yellow,
            "RadioButtonMenuItem.selectionBackground", GRAY_BLACK,
            "RadioButtonMenuItem.selectionForeground", yellow,
            "CheckBoxMenuItem.selectionBackground", GRAY_BLACK,
            "CheckBoxMenuItem.selectionForeground", yellow,
            
            // JTabbedPane background:
            "TabbedPane.contentAreaColor", grayLighter,
            "TabbedPane.selected", grayLighter,
            
            // TODO check why UIManager ignores this key
            "Table.dropCellBackground", GRAY_DARK,
            "Table.dropCellForeground", yellow,
            
            // UIs:
            "TextFieldUI", "org.tiberiumlabs.shards.components.ui.TextFieldUI",
            "PasswordFieldUI", "org.tiberiumlabs.shards.components.ui.PasswordFieldUI",
            "ListUI", "org.tiberiumlabs.shards.components.ui.ListUI",
            "TableUI", "org.tiberiumlabs.shards.components.ui.TableUI"
            
        };

        table.putDefaults(defaults);
        
        // just need to put it somewhere, can't find better place:
        ToolTipManager.sharedInstance().setInitialDelay(500);
    }

    @Override
    protected ColorUIResource getPrimary1() {
        return GRAY_BLACK;
    }

    @Override
    protected ColorUIResource getPrimary2() {
        // TODO combo boxes looks not very good
        return super.getPrimary2();
    }
    
    @Override
    protected ColorUIResource getPrimary3() {
        // TODO choose better color, because JTree ass-ugly
        return super.getPrimary3();
    }
    
    @Override
    protected ColorUIResource getSecondary2() {
        return GRAY_DARK;
    }

}
